package com.gurun.codes.business.common;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.gurun.base.DebounceObservableTransformer;
import com.gurun.codes.R;
import com.gurun.codes.business.home.MainActivityContract;
import com.gurun.codes.databinding.ItemContentBinding;
import com.gurun.codes.databinding.ItemHomeListBinding;
import com.gurun.model.bean.common.ListContentModel;
import com.gurun.model.bean.home.GetHomeListResultBean;
import com.jakewharton.rxbinding2.view.RxView;

import io.reactivex.functions.Consumer;

public class ListContentViewBinder extends me.drakeet.multitype.ItemViewBinder<ListContentModel, ListContentViewBinder.ViewHolder> {

    private Context mContext;

    public ListContentViewBinder(Context context) {
        mContext = context;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_content, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull ListContentModel item) {
        holder.bindData(item);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private ListContentModel mData;
        ItemContentBinding mBinding;

        public ViewHolder(View itemView) {
            super(itemView);
            mBinding = DataBindingUtil.bind(itemView);
        }


        public void bindData(ListContentModel item) {
            mData = item;
            if (mData != null) {
                mBinding.setData(mData);
                mBinding.ivPoint.setImageResource(mData.isFirstItem() ? R.mipmap.ic_record_top : R.mipmap.ic_record);
            }
        }
    }
}
